from django.db import models


class Technology(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=200)
    detail = models.TextField(max_length=10000, default='')

    class Meta:
        db_table = 'technology'
        ordering = ['id']


class Use(models.Model):
    pid = models.ForeignKey('project.Project', to_field='id', on_delete=models.CASCADE, db_column='pid')
    tid = models.ForeignKey('Technology', to_field='id', on_delete=models.PROTECT, db_column='tid')
    annotation = models.CharField(max_length=200, default='')

    class Meta:
        db_table = 'use'
        constraints = [
            models.UniqueConstraint(fields=['pid', 'tid'], name='use_id')
        ]


class Know(models.Model):
    uid = models.ForeignKey('user.User', to_field='id', on_delete=models.CASCADE, db_column='uid')
    tid = models.ForeignKey('Technology', to_field='id', on_delete=models.PROTECT, db_column='tid')
    annotation = models.CharField(max_length=200, default='')

    class Meta:
        db_table = 'know'
        constraints = [
            models.UniqueConstraint(fields=['uid', 'tid'], name='know_id')
        ]
